package xyz.haijin.zt.mysql.model;


import java.util.List;

/**
 * @Auther liuhaijin
 * @Date 2021/7/14
 */

/**
 * 分页信息
 */
public class PageInfo {
	/**
	 * 当前页数
	 */
	private Integer current;
	/**
	 * 每页显示数
	 */
	private Integer pageSize;
	/**
	 * 排序字段和方式
	 */
	private List<PageSortField> sortFields;
	/**
	 * 复杂查询条件
	 */
	private List<PredicateExpress> predicates;

	public Integer getCurrentOrDefault(Integer defaultVal){
		if(current==null){
			return defaultVal;
		}else {
			return current;
		}
	}
	public Integer getPageSizeOrDefault(Integer defalutVal){
		if(pageSize==null){
			return defalutVal;
		}else {
			return pageSize;
		}
	}

	public static class PageSortField {
		/**
		 * 字段名
		 */
		private String fieldName;
		/**
		 * 排序方式 升序asc 降序desc
		 */
		private String sortBy;

		public String getFieldName() {
			return fieldName;
		}

		public void setFieldName(String fieldName) {
			this.fieldName = fieldName;
		}

		public String getSortBy() {
			return sortBy;
		}

		public void setSortBy(String sortBy) {
			this.sortBy = sortBy;
		}

		@Override
		public String toString() {
			return "PageSortField{" +
					"fieldName='" + fieldName + '\'' +
					", sortBy='" + sortBy + '\'' +
					'}';
		}
	}

	public Integer getCurrent() {
		return current;
	}

	public void setCurrent(Integer current) {
		this.current = current;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public List<PageSortField> getSortFields() {
		return sortFields;
	}

	public void setSortFields(List<PageSortField> sortFields) {
		this.sortFields = sortFields;
	}

	public List<PredicateExpress> getPredicates() {
		return predicates;
	}

	public void setPredicates(List<PredicateExpress> predicates) {
		this.predicates = predicates;
	}

	@Override
	public String toString() {
		return "BasePageInfo{" +
				"current=" + current +
				", pageSize=" + pageSize +
				", sortFields=" + sortFields +
				", predicates=" + predicates +
				'}';
	}
}
